<p>Using the same value on either side of a binary operator is almost always a mistake. In the case of logical operators, it is either a copy/paste
error and therefore a bug, or it is simply wasted code, and should be simplified. In the case of bitwise operators and most binary mathematical
operators, having the same value on both sides of an operator yields predictable results, and should be simplified.</p>
<h2>Noncompliant Code Example</h2>
<pre>
if ( a == a ) { // always true
  doZ();
}
if ( a != a ) { // always false
  doY();
}
if ( a == b &amp;&amp; a == b ) { // if the first one is true, the second one is too
  doX();
}
if ( a == b || a == b ) { // if the first one is true, the second one is too
  doW();
}

int j = 5 / 5; //always 1
int k = 5 - 5; //always 0

c.equals(c); //always true
</pre>
<h2>Exceptions</h2>
<ul>
  <li> This rule ignores <code>*</code>, <code>+</code>, and <code>=</code>. </li>
  <li> The specific case of testing a floating point value against itself is a valid test for <code>NaN</code> and is therefore ignored. </li>
  <li> Similarly, left-shifting 1 onto 1 is common in the construction of bit masks, and is ignored. </li>
</ul>
<pre>
float f;
if(f != f) { //test for NaN value
  System.out.println("f is NaN");
}

int i = 1 &lt;&lt; 1; // Compliant
int j = a &lt;&lt; a; // Noncompliant
</pre>
<h2>See</h2>
<ul>
  <li> <a href="https://www.securecoding.cert.org/confluence/x/NYA5">CERT, MSC12-C.</a> - Detect and remove code that has no effect or is never
  executed </li>
  <li> {rule:java:S1656} - Implements a check on <code>=</code>. </li>
</ul>

